﻿using Common.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1.控件
{
    internal class ContorlGenerateHelper
    {
        public static void SetGridPropertyAndName(DataGridView dataGridView1, Type type)
        {
            var map = ReflectHelper.GetSqlEntityDesction(type);
            // 清空现有列
            dataGridView1.Columns.Clear();
            foreach (var col in map)
            {
                var column = new DataGridViewTextBoxColumn
                {
                    Name = col.Key,
                    HeaderText = col.Value,
                    DataPropertyName = col.Key,
                    AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
                };
                dataGridView1.Columns.Add(column);
            }
        }
    }
}
